package com.hucais.etl.history.dao

import com.hucais.etl.history.bean.{HistoryBcBook, HistoryKfzBookComment, HistoryKfzBookInformation, HistoryKfzBookStore}
import org.apache.spark.sql.{Dataset, SparkSession}

object HiveDao {
  /**
   * 获取中图网的书籍数据
   *
   * @param sparkSession
   * @return
   */
  def getBcBook(sparkSession: SparkSession): Dataset[HistoryBcBook] = {
    import sparkSession.implicits._
    sparkSession.sql(
      """
        |select
        |	isbn,book_name,pricing,sell_price,publishing_house,
        |	category,publishing_time,comment_number,author,impression,
        |	edition,binding_layout,formats,number_of_pages,
        |	slogan,number_of_suit
        |from published.bak_book_infomation_bc
        |""".stripMargin).as[HistoryBcBook]
  }

  /**
   * 获取孔夫子的书籍数据
   * @param sparkSession
   * @return
   */
  def getKfzBookInformation(sparkSession: SparkSession): Dataset[HistoryKfzBookInformation] = {
    import sparkSession.implicits._
    sparkSession.sql(
      """
        |select
        |	isbn,book_name,author,pricing,category,
        |	publishing_house,publishing_time,impression,edition,
        |	sales_volume,binding_layout,format,number_of_pages,paper,number_of_suit
        |from published.bak_book_information_kfz
        |""".stripMargin).as[HistoryKfzBookInformation]
  }

  /**
   * 获取孔夫子的书店数据
   * @param sparkSession
   * @return
   */
  def getKfzBookStore(sparkSession: SparkSession): Dataset[HistoryKfzBookStore] = {
    import sparkSession.implicits._
    sparkSession.sql(
      """
        |SELECT isbn,name_of_shop,slogan,book_review,selling_price,store_pricing,conditions,number
        |from published.bak_book_store_kfz
        |""".stripMargin).as[HistoryKfzBookStore]
  }

  /**
   * 获取孔夫子的评论数据
   * @param sparkSession
   * @return
   */
  def getBookKfzComment(sparkSession: SparkSession): Dataset[HistoryKfzBookComment] = {
    import sparkSession.implicits._
    sparkSession.sql(
      """
        |select store_name,book_name,username,comment_content,comment_time,score
        |from published.bak_book_comment_kfz
        |""".stripMargin).as[HistoryKfzBookComment]
  }
}
